package com.example.testapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.content.LocalBroadcastManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;


/**
 * @author wwq on 2019/7/18  17:31.
 */
public class MenuExpert extends Fragment {
    private LocalBroadcastManager localBroadcastManager;
    private EditText etInput;

    @Nullable
    @Override
    public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.menu_expert, container, false);


        Button btnSendLocal = view.findViewById(R.id.btnSendLocal);
        etInput = view.findViewById(R.id.etInput);
        btnSendLocal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                localBroadcastManager = LocalBroadcastManager.getInstance(getActivity());
                Intent intent = new Intent("com.example.LOCAL_BROADCAST");
                final String str = etInput.getText().toString();
                intent.putExtra("str", str);
                localBroadcastManager.sendBroadcast(intent);
            }
        });
        return view;
    }
}
